package com.cszjzx.member.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.cszjzx.member.po.Master;
import com.cszjzx.member.service.MasterService;
import com.cszjzx.member.service.MasterServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ManagementOfAdminAction extends ActionSupport {

	
	/**
	 * 管理员管理里面删除管理员只提供单个删除的功能
	 */
	private String masterId;
	private String password;
	private String message;
	private List<Master> masters;
	MasterService masterservice = new MasterServiceImpl();
	HttpServletRequest request = ServletActionContext.getRequest();
	Master master = (Master)request.getSession().getAttribute("master");
	

	public List<Master> getMasters() {
		return masters;
	}
	public void setMasters(List<Master> masters) {
		this.masters = masters;
	}

	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}

	public String getMasterId() {
		return masterId;
	}
	public void setMasterId(String masterId) {
		this.masterId = masterId;
	}

	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	

	/**
	 * 获取数据：无
	 * 作用：获取一个所有管理员的列表
	 * 转出：managementOfAdmin.jsp
	 * 提供数据：管理员列表
	 * @return
	 * @throws Exception
	 */
	public String show() throws Exception{

		masters = masterservice.getMasters(master.getModule());
		return "showAdmin";
	}
	
	/**
	 * 一个管理员对象
	 * 添加一个管理员
	 * 添加成功确认界面
	 * 无
	 * @return
	 * @throws Exception
	 */
	public String add() throws Exception{
		
		if(masterId.equals("")||password.equals("")){
			message="数据未输入，请输入数据！";
		}else{
			if(masterservice.addMaster(masterId, password,master.getModule())==true){
				message = "添加管理员成功";
			}else{
				message = "添加管理员失败";
			}
		}
		return "addAdmin";
	}
	
	/**
	 * 一个管理员的id
	 * 删除这些管理员
	 * 删除成功确认界面
	 * 无
	 * @return
	 * @throws Exception
	 */
	public String delete() throws Exception{
		
		if(masterservice.deleteMaster(masterId)==true){
			message = "删除管理员成功";
		}else{
			message = "删除管理员失败";
		}
		
		return "deleteAdmin";
	}
}
